/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package spaceconquest3d;

import com.jme3.app.SimpleApplication;

/**
 *
 * @author Michael
 */
public class GameManager {

    private GameState gameState = GameState.login;
    private static GameManager instance = null;
    private final Login login;
    private final Menue menue;
    private final PrepareBattle prepareBattle;
    private final Battle battle;
    private final Dead dead;
    private final Scoreboard scoreboard;

    public GameManager(SimpleApplication app) {
        login = new Login(app);
        menue = new Menue(app);
        prepareBattle = new PrepareBattle(app);
        battle = new Battle(app);
        dead = new Dead(app);
        scoreboard = new Scoreboard(app);
    }

    /**
     * Get a the instance of the GameManager.
     *
     * @return
     */
    public static GameManager getGameManager() {
        return instance;
    }

    /**
     * Get the current Gamestate.
     *
     * @return
     */
    public GameState getGameState() {
        return gameState;
    }
    
    public void changeGameState(GameState gameState) {
        unload();
        this.gameState = gameState;
        load();
    }

    /**
     * Call the update event of the correct class depending on the gamestate.
     *
     * @param tpf
     */
    public void update(float tpf) {
        switch (gameState) {
            case login:
                login.update(tpf);
                break;
            case menue:
                menue.update(tpf);
                break;
            case preparebattle:
                prepareBattle.update(tpf);
                break;
            case battle:
                battle.update(tpf);
                break;
            case dead:
                dead.update(tpf);
                break;
            case scoreboard:
                scoreboard.update(tpf);
                break;
        }
    }
    
    public void load() {
        switch (gameState) {
            case login:
                login.load();
                break;
            case menue:
                menue.load();
                break;
            case preparebattle:
                prepareBattle.load();
                break;
            case battle:
                battle.load();
                break;
            case dead:
                dead.load();
                break;
            case scoreboard:
                scoreboard.load();
                break;
        }
    }
    
    public void unload() {
        switch (gameState) {
            case login:
                login.unload();
                break;
            case menue:
                menue.unload();
                break;
            case preparebattle:
                prepareBattle.unload();
                break;
            case battle:
                battle.unload();
                break;
            case dead:
                dead.unload();
                break;
            case scoreboard:
                scoreboard.unload();
                break;
        }
    }
}
